package com.example.service.impl;

import com.example.entity.vote.VoteRecording;
import com.example.mapper.VoteMapper;
import com.example.service.VoteService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class VoteServiceImpl implements VoteService {

    @Resource
    VoteMapper mapper;

    @Override
    public List<Integer> getVoteCountByGid(int gid) {
        return mapper.getVoteCountByGid(gid);
    }

    @Override
    public List<Map<String, Integer>> getAllVoteCount() {
        return mapper.getAllVoteCount();
    }

    @Override
    public List<Map<String, Integer>> getAllVoteCountSinger() {
        return mapper.getAllVoteCountSinger();
    }

    @Override
    public Integer getVoteCountByUid(int uid) {
        return mapper.getVoteCountByUid(uid);
    }

    @Override
    public Integer isVoteReCording(VoteRecording voteRecording) {
        int result;
        if (voteRecording.getSid() == 0) {
            result = mapper.isVoteReCording(voteRecording);
        } else {
            result = mapper.isVoteReCordingSid(voteRecording);
        }
        return result == 1 ? 1 : (result == 0 ? 2 : 3);
    }

    @Override
    public String addVoteReCording(VoteRecording voteRecording) {
        return mapper.addVoteRecording(voteRecording) > 0 ? null : "添加投票记录失败";
    }

    @Override
    public String deleteVoteRecordingByUidAndGid(int sid, int uid, int gid) {
        return mapper.deleteVoteRecordingByUidAndGid(sid, uid, gid) > 0 ? null : "删除投票记录失败";
    }
}
